package cn.knightzz.service.impl;

import cn.knightzz.entity.SysMember;
import cn.knightzz.entity.SysUser;
import cn.knightzz.mapper.SysMemberMapper;
import cn.knightzz.mapper.SysUserMapper;
import cn.knightzz.mapper.SysUserMessageMapper;
import cn.knightzz.service.SysMemberService;
import cn.knightzz.service.SysUserService;
import cn.knightzz.vo.ExamineCountVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 党员表 服务实现类
 * </p>
 *
 * @author knightzz
 * @since 2021-05-14
 */
@Service
public class SysMemberServiceImpl extends ServiceImpl<SysMemberMapper, SysMember> implements SysMemberService {

    @Resource
    SysMemberMapper memberMapper;

    /**
     * 添加党员信息
     *
     * @param member
     * @return
     */
    @Override
    public Boolean addMember(SysMember member) {
        try {
            return memberMapper.insert(member) != 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 更新党员信息
     *
     * @param member
     * @return
     */
    @Override
    public Boolean updateMember(SysMember member) {
        try {
            return memberMapper.updateById(member) != 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 删除党员信息
     *
     * @param id
     * @return
     */
    @Override
    public Boolean deleteMember(Long id) {
        try {
            return memberMapper.deleteById(id) != 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 分页查询数据
     *
     * @param pageNum
     * @param pageSize
     * @param query
     * @return
     */
    @Override
    public IPage<SysMember> selectMemberPage(Long pageNum, Long pageSize, String query) {

        Page<SysMember> page = new Page<>();
        page.setSize(pageSize);
        page.setCurrent(pageNum);

        QueryWrapper<SysMember> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("name", query);

        try {
            return memberMapper.selectPage(page, queryWrapper);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 根据党员姓名模糊查询
     *
     * @param name
     * @return
     */
    @Override
    public List<SysMember> getMemberListByName(String name) {

        QueryWrapper<SysMember> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("name", name);

        try {
            return memberMapper.selectList(queryWrapper);
        } catch (Exception e) {
            e.printStackTrace();
            return new ArrayList<>();
        }
    }


}
